home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4535 < prev    next >
Encoding:
Text File  |  1996-08-06  |  4.1 KB  |  153 lines

  1. Path: owl.WPI.EDU!kevint
  2. From: kevint@wpi.edu (Kevin Theroux)
  3. Newsgroups: comp.lang.c++
  4. Subject: OWL:  Palette problem - Please HELP!
  5. Date: 30 Jan 1996 20:25:44 GMT
  6. Organization: Worcester Polytechnic Institute
  7. Message-ID: <4elus8$e5m@bigboote.WPI.EDU>
  8. NNTP-Posting-Host: owl.wpi.edu
  9. X-Newsreader: TIN [version 1.2 PL1]
  10.  
  11.  
  12.  
  13. Hi there,
  14. I hope someone out there can help...I'm really stuck and in a time cruch.
  15.  
  16. I am taking a course in Graphics and decided to use the PC for my projects.
  17. I just need to get a bare-bones app going so I can do my project.  I want
  18. to create a simple window, create a bitmap in the window (so I can draw
  19. to it), create a palette (aka color map) and get access to the palette to
  20. change colors.
  21.  
  22. I have everything working EXCEPT creating and modifying a palette.
  23. Can someome PLEASE help me out with this.  My code is below.
  24. If you already have a skeleton app that does what I'm looking for,
  25. could you please email it to me or tell me what I did wrong?
  26. (kevint@cs.wpi.edu)
  27.  
  28. The code I have for creating a palette came directly from a Borland
  29. example...but it doesn't work.  I'm using Borland C++ v4.5.
  30.  
  31. Thank you,
  32. Kevin Theroux   :-)
  33.  
  34. ============================================================================
  35.  
  36. #include <owl/owlpch.h>
  37. #include <owl/applicat.h>
  38. #include <owl/framewin.h>
  39. #include <owl/dc.h>
  40. #include <owl/inputdia.h>
  41. #include <owl/color.h>
  42. #include <stdlib.h>
  43.  
  44. /*------------------------------------------------------------------------*/
  45.  
  46. #define NUM_PALETTE_ENTRIES 128
  47.  
  48. /*------------------------------------------------------------------------*/
  49.  
  50. int          width, height;
  51. HPALETTE     hpal;
  52. PALETTEENTRY ape[NUM_PALETTE_ENTRIES];
  53. LOGPALETTE*  plgpl;
  54.  
  55. /*------------------------------------------------------------------------*/
  56.  
  57. class myWindow : public TWindow
  58. {
  59.   TMemoryDC *myMemoryBitmap;  // this is where to draw to, then it is
  60.                   // BitBlt'ed to the window
  61.  
  62.   public:
  63.      myWindow(TWindow* parent = 0);
  64.      void SetupWindow();
  65.     ~myWindow()
  66.      {
  67.      }
  68.  
  69.   protected:
  70.      // Message response functions
  71.  
  72.   void Paint(TDC& dc, BOOL erase, TRect& rect);
  73. };
  74.  
  75. /*------------------------------------------------------------------------*/
  76.  
  77. myWindow::myWindow(TWindow* parent)
  78. {
  79.     Init(parent, 0, 0);
  80. }
  81.  
  82. /*------------------------------------------------------------------------*/
  83.  
  84. void
  85. myWindow::Paint(TDC& dc, BOOL, TRect& )
  86. {
  87.     dc.BitBlt( GetClientRect(), *myMemoryBitmap, TPoint(0,0));
  88. }
  89.  
  90. /*------------------------------------------------------------------------*/
  91.  
  92. void
  93. myWindow::SetupWindow()
  94. {
  95.     int i, j, k, red, green, blue;
  96.  
  97.     TWindow::SetupWindow();
  98.  
  99.     myMemoryBitmap = new TMemoryDC( TClientDC (HWindow));
  100.     myMemoryBitmap->SelectObject (TBitmap (width, height, 1, 32));
  101.  
  102.     plgpl = (LOGPALETTE*) LocalAlloc (LPTR,
  103.         sizeof(LOGPALETTE) + NUM_PALETTE_ENTRIES * sizeof(PALETTEENTRY));
  104.  
  105.     plgpl->palNumEntries = NUM_PALETTE_ENTRIES;
  106.     plgpl->palVersion = 0x300;
  107.  
  108.     for (i = 0, red = 0, green = 127, blue = 127; i < NUM_PALETTE_ENTRIES;
  109.          i++, red += 1, green += 1, blue += 1)
  110.     {
  111.          ape[i].peRed   = plgpl->palPalEntry[i].peRed   = LOBYTE(red);
  112.          ape[i].peGreen = plgpl->palPalEntry[i].peGreen = LOBYTE(green);
  113.          ape[i].peBlue  = plgpl->palPalEntry[i].peBlue  = LOBYTE(blue);
  114.          ape[i].peFlags = plgpl->palPalEntry[i].peFlags = PC_RESERVED;
  115.     }
  116.  
  117.     hpal = CreatePalette(plgpl);  // * *  THIS ALWAYS RETURNS NULL  * *
  118.  
  119.     AnimatePalette(hpal, 0, NUM_PALETTE_ENTRIES,
  120.                        (PALETTEENTRY FAR*) &ape);
  121. }
  122.  
  123. /*------------------------------------------------------------------------*/
  124.  
  125. class myApp : public TApplication {
  126.   public:
  127.      myApp() : TApplication() {}
  128.  
  129.      void InitMainWindow()
  130.      {
  131.         TFrameWindow *my_FrameWindow = \
  132.             new TFrameWindow(0, "Draw", new myWindow(0), true);
  133.         
  134.         width  = TScreenDC().GetDeviceCaps( HORZRES );
  135.         height = TScreenDC().GetDeviceCaps( VERTRES );
  136.  
  137.         my_FrameWindow->Attr.X = (width -600)/2;
  138.         my_FrameWindow->Attr.Y = (height-400)/2-20;
  139.  
  140.         SetMainWindow (my_FrameWindow);
  141.      }
  142. };
  143.  
  144. /*------------------------------------------------------------------------*/
  145.  
  146. int
  147. OwlMain(int /*argc*/, char* /*argv*/ [])
  148. {
  149.   return myApp().Run();
  150. }
  151.  
  152. /*------------------------------------------------------------------------*/
  153.